package cn.gok.oa.information.controller;


import cn.gok.oa.information.dto.CommentDto;
import cn.gok.oa.information.dto.InformationDto;
import cn.gok.oa.information.entity.TbComment;
import cn.gok.oa.information.entity.TbInformation;
import cn.gok.oa.information.service.impl.TbCommentServiceImpl;
import cn.gok.oa.information.vo.CommentVo;
import cn.gok.oa.log.LogAnnotation;
import cn.gok.oa.system.vo.UserListVo;
import cn.gok.oa.util.ResultData;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gok
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/information/comment")
public class TbCommentController {
    @Autowired
    TbCommentServiceImpl tbCommentService;

    @RequestMapping(value = "/add" )
    @LogAnnotation("添加评论")
    public ResultData addComment(@RequestBody TbComment comment){
        if(tbCommentService.save(comment))
            return ResultData.success();
        else
            return ResultData.fail();
    }

    @RequestMapping(value = "/deleteComment")
    @LogAnnotation("删除评论")
    public ResultData deleteComment(@Param("id") Integer id){
        if(tbCommentService.removeById(id))
            return ResultData.success();
        else
            return ResultData.fail();
    }

    @RequestMapping(value = "/info" )
    @LogAnnotation("获取全部评论列表")
    @ResponseBody
    public ResultData info(CommentDto commentDto){
        Page<CommentVo> page = new Page<>(commentDto.getPage(),commentDto.getLimit());
        IPage<CommentVo> iPage = tbCommentService.selectCommentList(page,commentDto.getSearch());
        return ResultData.page(iPage.getRecords(),iPage.getTotal());
    }

}